package main

import (
	"context"
	"fmt"

	httpClient "github.com/asim/go-micro/plugins/client/http/v3"
	"github.com/asim/go-micro/v3/client"
	"github.com/asim/go-micro/v3/registry"
	"github.com/asim/go-micro/v3/selector"
)

const (
	SERVER_NAME = "user-http"
	SERVER_METHOD = "/info"
)

func main() {
	// 创建 registry 和 selector
	r := registry.NewRegistry()
	s := selector.NewSelector(selector.Registry(r))

	// 创建客户端
	c := httpClient.NewClient(client.Selector(s))

	// 创建请求和返回
	req := c.NewRequest(
		SERVER_NAME,
		SERVER_METHOD,
		"",
		client.WithContentType("application/json"),
	)
	rsp := new(map[string]interface{})

	// 调用
	if err := c.Call(context.Background(), req, rsp); err != nil {
		panic(err)
	}
	fmt.Println("call server success: ", rsp)
}
